package com.example.springboot.modules.order.controller;

import com.example.springboot.common.controller.BaseController;
import com.example.springboot.common.utils.JsonResult;
import com.example.springboot.modules.order.model.Purchase;
import com.example.springboot.modules.order.service.PurchaseService;
import com.example.springboot.modules.order.utils.PurchaseUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zql on 2018/7/15.
 */
@Controller
@RequestMapping("/purchase")
public class PurchaseController extends BaseController{

    @Autowired
    private PurchaseService purchaseService;

    @RequestMapping(value="/toPurchase",method = RequestMethod.GET)
    public String toPurchase(){
        return "order/purchase_list";
    }

    @RequestMapping(value="/toForm",method = RequestMethod.GET)
    public String toForm(){
        return "order/purchase_form";
    }

    @RequestMapping(value="/selectAll" ,method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> selectAll(Purchase key){
        List<Purchase> purchase=null;
        purchase=purchaseService.selectAll(key);
        PageInfo<Purchase> pageInfo=new PageInfo<>(purchase);
        resultMap.put("code","0");
        resultMap.put("msg","");
        resultMap.put("data", purchaseService.parseVoList(pageInfo.getList()));
        resultMap.put("count",pageInfo.getTotal());
        return resultMap;
    }



}
